/**************************************************************************************************
  Filename:       logic_handler.h
  Revised:        $Date: 2014-12-08 10:20:18 +0800 (Fri, 04 Apr 2014) $
  Revision:       $Revision: 10001 $

  Description:    This file contains the main logic of the whole system. 
**************************************************************************************************/

#ifndef __LOGIC_HANDLER_H__
#define __LOGIC_HANDLER_H__

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdio.h>
#include <stdlib.h>

#include "hal_types.h"
#include "hal_timer.h"
#include "comdef.h"
#include "bcomdef.h"
 
#include "OSAL.h"
#include "OSAL_Clock.h"
#include "peripheral.h"
#include "hal_drivers.h"
#include "ioCC2541.h"
#include "hal_mcu.h"
#include "bsp_storage.h"

#include "hal_sht.h"
  
#include "battprofile.h"
#include "dataservice.h"
#include "heimdallr.h"

  


// #define MOTION_SHAKE_HARD 	0x01
// Hardware interrupts solved 
#define MOTION_TAP 			0x02
#define MOTION_TURN         0x07

// Counting steps  Program 
#define MOTION_CLIMB 		0x03
#define MOTION_WALK 		0x04

//	#define MOTION_RUN 			0x05

// #define MOTION_TAKE			0x08

// #define MOTION_JUMP 		0x06

#define SLEEP_TIME

//Baoqi
//shimianshijian


#define BC_HUMI_EVENT 0x01
#define BC_BATT_EVENT 0x02
#define BC_POST_EVENT 0x04

#define NEED_CONFIRM_TURN_ON 0x01
#define NEED_CONFIRM_TURN_OFF 0x02


extern bStatus_t dataHandler(UnitData unit);
extern bool isConnected(void);
extern bStatus_t motionHandler(uint8 taskID,uint8 paramID);
extern bStatus_t udStrHandler(uint8 *string);
extern bStatus_t syncHandler(uint8 taskID,uint8 suid);

extern bStatus_t broadcastHanler(uint8 paramID);


extern uint16 get_middle_one(uint16 *buf);
// Already clear status bits
extern uint8 HumiProcess(uint16 humidata,uint16 tempdata);
extern void SleepProcess(uint8 *result);
extern void BattHandler(void);
extern void motionProcess();

extern const uint32 dataSectorAddrs[DATA_SECTOR_COUNT];

extern bStatus_t infoHandler(uint8 taskID,uint8 *string);

extern void cmd_crud(PACKHEAD ph);
extern void execute_funcmd(PACKHEAD ph);
extern bStatus_t startSendSetting(uint8 taskID,uint8 list);
// void prepend(uint8 *string,uint8 pre,uint8 *buf,uint8 length);
// void prepend12(uint8 *string,uint8 pre,uint8 *buf);
void settingNotify(uint8 taskID,uint8 *buf,uint8 len,uint8 datatype);
bStatus_t startSendSetting(uint8 taskID,uint8 list);


#ifdef __cplusplus
}
#endif

#endif

